package de.tub.bazinga.audio;

import processing.core.PApplet;
import ddf.minim.AudioPlayer;
import ddf.minim.Minim;

public class AudioManagerImpl implements IAudioManager {

	/**
	 * Singleton
	 */
	private static AudioManagerImpl instance;

	private static final String SOUND_HIT = "./sounds/hit/boom.mp3";

	private AudioPlayer sampleHit = null;

	private AudioManagerImpl(PApplet p) {
		Minim minim = new Minim(p);
		sampleHit = minim.loadFile(SOUND_HIT);
	}

	@Override
	public void playHitSound() {
		sampleHit.rewind();
		sampleHit.play();
	}

	@Override
	public void playGameFinishedSound() {
		throw new RuntimeException("Not yet implemented");

	}

	@Override
	public void playGameStartSound() {
		throw new RuntimeException("Not yet implemented");
	}

	public synchronized static void init(PApplet p) {
		if (instance != null) {
			throw new RuntimeException("Already Initialized!");
		}
		instance = new AudioManagerImpl(p);
	}

	public static IAudioManager getInstance() {
		if (instance == null) {
			throw new RuntimeException("Not Initialized! Call init first!");
		}
		return instance;
	}

}
